﻿using System;
using System.Collections;
using System.Windows.Forms;
using phhui;
using System.Xml;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;

namespace XmlHelper_use_demo
{
    public partial class Form1 : Form
    {
        private XmlHelper xml;
        private XmlDocument doc;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            xml = new XmlHelper();
            Random rd = new Random();
            int i = rd.Next();
            tb.Text = DateTime.Now.ToString("yyyy/MM/dd/hhmmss")+"--"+i.ToString();
        }

        private void btn_create_Click(object sender, EventArgs e)
        {
            xml.CreateXmlDocument("db/data.xml", "data", "GB2312");
        }

        private void btn_add_Click(object sender, EventArgs e)
        {
            Hashtable ht = new Hashtable();
            ht.Add("id","1003");
            xml.InsertNode("db/data.xml", "item",true,"data",ht,null);
        }

        private void btn_edit_Click(object sender, EventArgs e)
        {
            Dictionary<string,string> ht = new Dictionary<string, string>();
            ht.Add("id", "1000");//要修改的属性和值
            Dictionary<string, string> htt = new Dictionary<string, string>();
            htt.Add("id", "1003");//修改后的属性和值
            string text = "abc";//要修改的节点innerText
            xml.UpdateNode("db/data.xml", "data", ht, htt,text);
        }

        private void btn_delete_Click(object sender, EventArgs e)
        {
            //xml.DeleteNodes("db/data.xml", "//data//item");//删除节点data下的item节点的所有子节点
            Dictionary<string,string> ht = new Dictionary<string, string>();
            ht.Add("id", "10000");//删除data节点下id为10000的子节点
            xml.DeleteNodes("db/data.xml","data",ht);
        }
    }
}
